package swing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;

public class SwingButtonExample extends JFrame implements ActionListener{
	
	private JTextArea text;
	private JCheckBox checkD, checkE, checkF;
	private JButton buttonA, buttonB, buttonC;
	
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == buttonA){
			text.setText("CheckD: "+checkD.getModel().isSelected());
		}else if(e.getSource() == buttonB){
			text.setText("CheckE: "+checkE.getModel().isSelected());			
			if(checkF.getModel().isSelected()){text.setBackground(Color.CYAN);}else{text.setBackground(Color.WHITE);};			
		}else if(e.getSource() == buttonC){
			System.exit(0);
		}
	}
	
	public SwingButtonExample() {
		setTitle("My Frame"); 
		setSize(400, 150); 
		setLocationRelativeTo(null);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
		
		setLayout(new BorderLayout());
		
		text = new JTextArea();
		add(text, BorderLayout.CENTER);
		
		LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();
		for(LookAndFeelInfo lookAndFeelInfo : lookAndFeelInfos){
			text.setText(text.getText()+"\n"+lookAndFeelInfo.getClassName());
		}
		
		JPanel panel = new JPanel();
		panel.setLayout(new GridLayout(1,3));		
		panel.add(buttonA = new JButton("A"));
		panel.add(buttonB = new JButton("B"));
		panel.add(buttonC = new JButton("C"));		
		add(panel, BorderLayout.SOUTH);
		
		JPanel panel2 = new JPanel();
		panel2.setLayout(new GridLayout(3,1));
		panel2.add(checkD = new JCheckBox("Checkbox D"));
		panel2.add(checkE = new JCheckBox("Checkbox E"));
		panel2.add(checkF = new JCheckBox("Checkbox F"));
		add(panel2, BorderLayout.EAST);
		
		buttonA.addActionListener(this);
		buttonB.addActionListener(this);
		buttonC.addActionListener(this);
		
		buttonA.addActionListener(new ActionListener() {
					
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
			
		});
		
		setVisible(true); 
	}

	public static void main(String args[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
//		UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//		UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
//		UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//		UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
		new SwingButtonExample();
	}

}

